<template>
  <router-link v-if="!subMenus" class="menu-item" :to="path">
    <Item :name="name"><slot></slot></Item>
  </router-link>
  <el-dropdown v-else @command="handleCommand">
    <div class="menu-item">
      <Item :name="name"><slot></slot></Item>
    </div>
    <template #dropdown>
      <el-dropdown-menu>
        <el-dropdown-item
          v-for="item in subMenus"
          :key="item.name"
          :command="item.name"
          >{{ item.meta.title }}</el-dropdown-item
        >
      </el-dropdown-menu>
    </template>
  </el-dropdown>
</template>
<script lang="ts" setup>
import { useRouter } from "vue-router";
import Item from "./Item.vue";
const props = defineProps<{
  name: string;
  path?: string;
  subMenus?: any[];
}>();
const router = useRouter();
const handleCommand = (command: string) => {
  router.push({ name: command });
};
</script>
<style lang="scss" scoped>
.menu-item {
  width: var(--el-header-height);
  height: var(--el-header-height);
  display: flex;
  justify-content: center;
  flex-direction: column;
  align-items: center;
  margin: 0 20px;
  color: black;
  cursor: pointer;
  transition-duration: 0.32s;
  transition-property: background-color;
  transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);

  &:hover {
    background-color: rgb(200, 210, 231);
  }
  @media screen and (max-width: 640px) {
    margin: 0;
  }
  @media screen and (max-width: 500px) {
    width: 60px;
  }
}
</style>
